package com.hqw.jzdemo.view;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.hqw.jzdemo.util.LogUtil;

import java.util.Map;

/**
 * Created by tiangui on 2020/01/13.
 */
@ReactModule(name = ReactJzAdViewManager.REACT_CLASS)
public class ReactJzAdViewManager extends SimpleViewManager<ReactJzAdView> {

    private static final String TAG = "ReactNative-jz";

    public static final String REACT_CLASS = "ReactJzAdView";

    public static final int COMMAND_requestAd = 1;
//    public static final int COMMAND_GO_FORWARD = 2;

    @Override
    public String getName() {
        return REACT_CLASS;
    }

    @Override
    protected ReactJzAdView createViewInstance(ThemedReactContext reactContext) {
        LogUtil.i(TAG, "createViewInstance()");
        return new ReactJzAdView(reactContext, null);
    }

    @Override
    public Map<String, Integer> getCommandsMap() {
        return MapBuilder.of(
                "requestAd", COMMAND_requestAd
//                "setPageWithoutAnimation", COMMAND_SET_PAGE_WITHOUT_ANIMATION
        );
    }

    // todo 暂时还是用这个即将废弃的方法
    @Override
    public void receiveCommand(@NonNull ReactJzAdView view, int commandId, @Nullable ReadableArray args) {
        LogUtil.i(TAG, "receiveCommand(): commandId = " + commandId);
        switch (commandId) {
            case COMMAND_requestAd:
                view.requestAd();
                return;
        }
    }

    @Override
    public @Nullable Map<String, Object> getExportedCustomDirectEventTypeConstants() {
        return super.getExportedCustomDirectEventTypeConstants();
    }

}
